<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>收款单登记表新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">收款单信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">登记公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="hrOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">登记部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">登记人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">费用归属公司</label>
				      		<div class="layui-input-inline">
				        		<select name="hrOrgBillId" lay-verify="required"  lay-search>
				              		<c:if test="${not empty orgInfos }">
				              			<c:forEach items="${orgInfos}" var="org">
				              				<option value="${org.id }" <c:if test="${org.id == bindOrgId }">selected</c:if>>${org.compName }</option>
					            		</c:forEach>
				              		</c:if>
				              	</select>
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">结算方式</label>
				      		<div class="layui-input-inline">
				        		<infopub:select id="add-form-settle" entireName="-结算方式" name="settlementMode" layVerify="required" type="dic" groupNo="A00010063"></infopub:select>
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">收款类型</label>
				      		<div class="layui-input-inline">
				        		<infopub:select id="add-form-type" entireName="-收款类型" name="incomeType" layVerify="required" layFilter="add-form-type" type="dic" groupNo="A00010064"></infopub:select>
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">收款日期</label>
				      		<div class="layui-input-inline">
				      			<input type="text" class="layui-input" id="sent-laydate-income" name="incomeDate" lay-verify="required" readonly>
				      		</div>
					    </div>
				  		<div class="layui-inline">
					    	<label class="layui-form-label">收款总额（元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" id="actIncomeAmount" name="actIncomeAmount" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">收款摘要</label>
				      		<div class="layui-input-inline">
				      			<textarea name="incomeSummary" maxlength="500" placeholder="请输入收款摘要" lay-verify="required" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		 <div class="layui-inline">
					    	<label class="layui-form-label">备注（选填）</label>
				      		<div class="layui-input-inline">
				      			<textarea name="memo" maxlength="500" placeholder="请输入备注" class="layui-textarea" style="width:899px;height:90px;"></textarea>
				      		</div>
					    </div>
				    </div>
		  		</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="detailInfo" style="display:none">
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">回购款明细 ></legend>
			  	<div style="margin-top:20px">
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">可用性服务费（元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="usableServiceFee" name="usableServiceFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">政策处理费（元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="policyTreatFee" name="policyTreatFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">使用者服务费（元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="userServiceFee" name="userServiceFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
					</div>
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">可行性缺口补助（元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="gapSubsidyFee" name="gapSubsidyFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label">运营维护费（元）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" id="omFee" name="omFee" maxlength="13" onblur="isNumberFloat(this);arabiaToCN(this,1);" value="0" lay-verify="required|floatNumber" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					      	<label class="layui-form-label">竣工结算款（元）</label>
					      	<div class="layui-input-inline">
					        	<input type="text" id="completeFee" name="completeFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
					      	</div>
					    </div>
				    </div>
			  		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">保修金（元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="keepFee" name="keepFee" onblur="isNumberFloat(this);arabiaToCN(this,1);" maxlength="13" value="0" lay-verify="required|floatNumber" class="layui-input">
				      		</div>
					    </div>
				    </div>
			  	</div>
			</fieldset>
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-income'
    });
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
    
  	//收款类型select监听
    form.on('select(add-form-type)', function(data){
    	var takeType = data.value;
    	if(takeType == null || takeType == ''){
    		return;
    	}
    	if(takeType == '9'){//回购款
    		$("#actIncomeAmount").val('');
    		$("#actIncomeAmount").css("border","0px");
    		$("#actIncomeAmount").attr("readonly","readonly");
    		$("#actIncomeAmount").removeAttr("lay-verify").removeAttr("onblur");
    		$("#detailInfo").find("input").removeAttr("style");
    		$("#detailInfo").find("input").removeAttr("readonly");
    		$("#detailInfo").find("input").val('');
    		$("#detailInfo").show();
    		form.render();
    	}else{
    		$("#actIncomeAmount").removeAttr("style").removeAttr("readonly");
    		$("#actIncomeAmount").attr("lay-verify","required|floatNumber");
    		$("#actIncomeAmount").attr("onblur","isNumberFloat(this);arabiaToCN(this,1);");
    		$("#detailInfo").hide();
    		$("#detailInfo").find("input").val(0);
    		$("#detailInfo").find("input").css("border","0px");
    		$("#detailInfo").find("input").attr("readonly","readonly");
    	}
	});
  	
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/incomeBill/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/incomeBill/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '收款单登记表';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/incomeBill/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  
	//验证金额
	function isNumberFloat(obj){
		var $ = layui.$;
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(obj.value);// true 
		if (!boolrgx){
			obj.value=0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		var name = obj.name;
		if(name != 'actIncomeAmount'){
			calcSumAmount();
		}
	}
  
	//计算收款总额
	function calcSumAmount(){
		var $ = layui.$;
		var usableServiceFee = $("#usableServiceFee").val();
		var policyTreatFee = $("#policyTreatFee").val();
		var userServiceFee = $("#userServiceFee").val();
		var gapSubsidyFee = $("#gapSubsidyFee").val();
		var omFee = $("#omFee").val();
		var completeFee = $("#completeFee").val();
		var keepFee = $("#keepFee").val();
		var totalAmount = 0;
		if(usableServiceFee != '' && parseFloat(usableServiceFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(usableServiceFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(policyTreatFee != '' && parseFloat(policyTreatFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(policyTreatFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(userServiceFee != '' && parseFloat(userServiceFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(userServiceFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(gapSubsidyFee != '' && parseFloat(gapSubsidyFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(gapSubsidyFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(omFee != '' && parseFloat(omFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(omFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(completeFee != '' && parseFloat(completeFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(completeFee);
			totalAmount = totalAmount.toFixed(2);
		}
		if(keepFee != '' && parseFloat(keepFee) > 0){
			totalAmount = parseFloat(totalAmount) + parseFloat(keepFee);
			totalAmount = totalAmount.toFixed(2);
		}
		$("#actIncomeAmount").val(totalAmount);
	}
  </script>
</body>
</html>

